<?php
/**
 * Created by PhpStorm.
 * User: ybjaa
 * Date: 2017/5/4
 * Time: 10:14
 */

namespace App\Business\Menu;

use App\Business\Model\Menu;
use App\Models\menus_manage;
use App\Units;

class GetCustomMenus extends MenusBase
{

    protected function Handle()
    {

        $menus= menus_manage::all();

        if($menus==null || count($menus)<=0) return [];

        //转化为业务模型对象
        $menus=Units::ArrayToObject($menus->toArray(),Menu::class);

        //获取顶层菜单
        $topMenus=array_filter($menus,function($m){
            return $m->parentID===0;
        });

        //排序
        $topMenus=$this->menuSort($topMenus);
        $this->recursion(array_values($topMenus),$menus);

        //TODO 过滤掉权限之类的数据



        return array_values($topMenus);
    }



    public function GetBusinessName()
    {
        return "获得用户菜单";
    }








}